//
//  WeMyAuctionController.m
//  WeGalaxy
//
//  Created by Zheng on 2017/7/7.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "WeMyAuctionController.h"
#import "WeMyAuctionTopSelectView.h"
#import "WeMyAuctionCell.h"

static NSString *kWeMyAuctionCell_ID = @"kWeMyAuctionCell_ID";

@interface WeMyAuctionController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) WeMyAuctionTopSelectView *topSelectView;
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic) WeMyAuctionTopSelectType selectType;

@end

@implementation WeMyAuctionController

#pragma mark - 点击事件
- (void)topButtonClickActionWithType:(WeMyAuctionTopSelectType)type {
    
    _selectType = type;
    
    switch (type) {
        case WeMyAuctionTopSelectTypeCompete:
            kCX_LOG(@"点击了参拍的");
            break;
        case WeMyAuctionTopSelectTypeFinish:
            kCX_LOG(@"点击了已结束");
            break;
        case WeMyAuctionTopSelectTypeOrder:
            kCX_LOG(@"点击了订单");
            break;
    }
    
    [self.myTableView reloadData];
}

- (void)outClickActionWithIndexPath:(NSIndexPath *)indexPath {
    kCX_LOG(@"%@", [NSString stringWithFormat:@"点击了(%ld,%ld)出局",indexPath.section,indexPath.row]);
}


- (void)offerClickActionWithIndexPath:(NSIndexPath *)indexPath {
    kCX_LOG(@"%@", [NSString stringWithFormat:@"点击了(%ld,%ld)出价",indexPath.section,indexPath.row]);
}

#pragma mark - tableview datasource & tableview delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WeMyAuctionCell *cell = [tableView dequeueReusableCellWithIdentifier:kWeMyAuctionCell_ID forIndexPath:indexPath];
    
    __weak typeof(self) weakSelf = self;
    
    cell.type = _selectType;
    
    [cell clickOutBtnWithIndexPath:indexPath withClickBlock:^(NSIndexPath *indexPath) {
        [weakSelf outClickActionWithIndexPath:indexPath];
    }];
    
    [cell clickOfferBtnWithIndexPath:indexPath withClickBlock:^(NSIndexPath *indexPath) {
        [weakSelf offerClickActionWithIndexPath:indexPath];
    }];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 155.f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return .001f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return .001f;
}


#pragma mark - 子视图
- (void)subviewsInView {
    
    [self.view addSubview:self.topSelectView];
    
    [_topSelectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.mas_equalTo(@52);
    }];
    
    [self.view addSubview:self.myTableView];
    
    [_myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.view);
        make.top.equalTo(_topSelectView.mas_bottom);
    }];
}

- (WeMyAuctionTopSelectView *)topSelectView {
    if (!_topSelectView) {
        _topSelectView = [[WeMyAuctionTopSelectView alloc] init];
        __weak typeof(self) weakSelf = self;
        _topSelectView.selectTypeBlock = ^(WeMyAuctionTopSelectType type) {
            [weakSelf topButtonClickActionWithType:type];
        };
    }
    return _topSelectView;
}

- (UITableView *)myTableView {
    if (!_myTableView) {
        _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_myTableView registerClass:[WeMyAuctionCell class] forCellReuseIdentifier:kWeMyAuctionCell_ID];
    }
    return _myTableView;
}

#pragma mark - 视图生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"我的拍卖";
    
    _selectType = WeMyAuctionTopSelectTypeCompete;
    
    [self subviewsInView];

}

#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
